module.exports = {
	/**
	 * 修改数据
	 * @url admin/recharge/sys/update 前端调用的url参数地址
	 * data 请求参数 说明
	 * res 返回参数说明
	 * @params {Number} code 错误码，0表示成功
	 * @params {String} msg 详细信息
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			_id,
			uid,
			tvinfo,
			recharge_amount,
			bean,
			recharge_text,
			subject,
			days,
			hour,
			judge,
			jiaobiao,
			invite_code,
			appid,
			appname,
			sort,
			give_bean, //多送多少豆
			percentage_user, //xx%的用户选择
			indulgence, //是否特惠充值
			tv_id,
			showFinger,
			_add_time,
			_add_time_str
		} = data;
		let res = {
			code: 0,
			msg: 'ok'
		};
		try {
			console.log("data=", data._id);
			//通过data._id获取旧数据
			let old_datas = await db.collection('b_recharge').doc(data._id).get()
			//记录操作日志到数据库
			let addlogs = await vk.baseDao.add({
				dbName: "opendb-admin-log",
				dataJson: {
					type: "update",
					path: "admin/pages/kh/xcxpz/chfagl/update",
					edit_log: data, //本次修改了哪些内容
					obj_id: old_datas.data[0]._id,
					old_data: old_datas.data[0],
					new_data: data,
					user_id: userInfo._id,
					user_name: userInfo.username,
					nick_name: userInfo.nickname,
					ip: originalParam.context.CLIENTIP,
					ua: originalParam.context.CLIENTUA
				}
			});
			// 业务逻辑开始-----------------------------------------------------------
		} catch (err) {
			console.log("日志加入失败");
		}
		// 业务逻辑开始-----------------------------------------------------------
		// 获取前端传过来的参数
		try {
			_id = tvinfo._id,
				recharge_amount = tvinfo.recharge_amount,
				bean = tvinfo.bean,
				recharge_text = tvinfo.recharge_text,
				subject = tvinfo.subject,
				days = tvinfo.days,
				hour = tvinfo.hour,
				judge = tvinfo.judge,
				jiaobiao = tvinfo.jiaobiao,
				invite_code = tvinfo.invite_code,
				appid = tvinfo.appid,
				appname = tvinfo.appname,
				sort = tvinfo.sort,
				give_bean = tvinfo.give_bean, //多送多少豆
				percentage_user = tvinfo.percentage_user, //xx%的用户选择
				indulgence = tvinfo.indulgence, //是否特惠充值
				_add_time = tvinfo._add_time,
				_add_time_str = tvinfo._add_time_str,
				tv_id = tvinfo.tv_id,
				showFinger = tvinfo.showFinger
		} catch (err) {

		}
		// 参数验证开始
		if (vk.pubfn.isNull(_id)) return {
			code: -1,
			msg: 'id不能为空'
		};


		// 参数验证结束
		let dbName = "b_recharge"; // 表名
		// 执行 数据库 updateById 命令
		await vk.baseDao.updateById({
			dbName,
			id: _id,
			dataJson: {
				recharge_amount,
				bean,
				jiaobiao,
				recharge_text,
				subject,
				days,
				hour,
				judge,
				give_bean, //多送多少豆
				percentage_user, //xx%的用户选择
				indulgence, //是否特惠充值
				sort,
				invite_code,
				appid,
				appname,
				tv_id,
				showFinger,
				_add_time,
				_add_time_str
			}
		});
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}

}